<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>apk信息</title>
	<link rel="stylesheet" type="text/css" href="/css/login.css">
	<script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="/js/vue.js"></script>
	<script type="text/javascript" src="/js/config.js"></script>
	<script type="text/javascript" src="/js/jquery.serializejson.js"></script>
	<script type="text/javascript" src="/js/layer/layer.js"></script>
	<script type="text/javascript" src="/js/paging.js"></script>
</head>
<body style="background:#fff;">
<form id="searchForm">
	<div class="search-bar clearfix panel" style="height: auto;padding-bottom: 0px;">
		<div class="box">
			<div class="cell-search" >
				<label>选择分类</label>
				<select name="apkKey">
					<option value="">全部分类</option>
					<option value="anpxdAndroidErpApp">Android</option>
					<option value="anpxdIOSErpApp">IOS</option>
				</select>
			</div>
			<div class="search-btn-box">
				<button type="button" id="serchApk">查询</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" src="../js/search.js"></script>
<div class="" id="app">
	<table style="width: 100%">
		<tr>
			<td style="text-align: left"><a onclick="newApk()"  class="add-button  opr-url">新增Apk信息</a></td>
		</tr>
	</table>

	<table class="list-box gate-table">
		<thead>
		<tr>
			<th>Apk分类</th>
			<th>Apk名称</th>
			<th>Apk版本号</th>
			<th>Apk热更新版本号</th>
			<th>Apk是否强制更新</th>
			<th>Apk下载地址</th>
			<th>Apk备注</th>
			<th>Apk状态</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody>
		<tr v-for="re in res">
			<td>
				<p>{{re.apkKey == "anpxdAndroidErpApp" ? "Android" : "IOS"}}</p>
			</td>
			<td>
				<p>{{re.apkName}}</p>
			</td>
			<td>
				<p>{{re.apkVersion}}</p>
			</td>
			<td>
				<p>{{re.apkHotVersion}}</p>
			</td>
			<td>
				<p>{{re.apkForce == 0 ? "否" : "是"}}</p>
			</td>
			<td>
				<p>{{re.apkUrl}}</p>
			</td>
			<td>
				<p>{{re.apkRemark}}</p>
			</td>
			<td>
				<p>{{re.apkState == 1 ? "有效" : "无效"}}</p>
			</td>
			<td>
				<a href='#' class="over-small" v-bind:data-apkId="re.apkId"  onclick="editApk(this)">编辑</a>
			</td>
		</tr>
		</tbody>
	</table>
	<!-- 编辑Apk信息  -->
	<form class="cell-content" id="updateApkForm" style="display: none;" >
		<div class="cell">
			<label><span class="red">*</span>Apk分类</label>
			<select id="updateApkKey" name="apkKey" v-model="apk.apkKey">
				<option value="anpxdAndroidErpApp">Android</option>
				<option value="anpxdIOSErpApp">IOS</option>
			</select>
		</div>

		<div class="cell">
			<label><span class="red">*</span>Apk名称</label>
			<input type="text" name="apkName" id="apkName" v-model="apk.apkName">
		</div>
		<div class="cell">
			<label><span class="red">*</span>Apk版本号</label>
			<input type="text" name="apkVersion" id="apkVersion" v-model="apk.apkVersion">
		</div>

		<div class="cell">
			<label><span class="red">*</span>Apk下载地址</label>
			<input type="text" name="apkUrl" id="updateApkUrl" v-model="apk.apkUrl">
		</div>
		<div class="cell">
			<label>Apk热更新版本号</label>
			<input type="text" name="apkHotVersion" id="apkHotVersion" v-model="apk.apkHotVersion">
		</div>
		<div class="cell">
			<label>Apk备注</label>
			<input type="text" name="apkRemark" id="apkRemark" v-model="apk.apkRemark">
		</div>

		<div class="cell">
			<input type="text" style="display: none;" id="versionList" name = "versionList" v-model="versionOption" >
			<label style="float: left">选择强制更新版本</label>
			<div class="version-box">
				<div v-for="version in versionList" v-if="version.apkId != apk.apkId ">
					<input type="checkbox" class="version-option" :id="version.apkId" v-model="versionOption" :value="version.apkId" >
					<label :for="version.apkId" class="version-option-txt" >{{version.apkVersion}}</label>
				</div>
			</div>
			<table></table>
		</div>
	</form>
</div>
<div id="page" class="page_div"></div>
<style>
	.version-option{
		display: inline-block;
		margin:0;
		width: 15px;
		height:15px;
		padding: 0;
	}
	.version-box{max-height:200px;
		min-height:50px;
		min-width: 200px;
		border:solid 0.9px #c9c9c9;
		clear: both;
		float: left;
		overflow-y: auto; background: #FFFFE0 ;margin-left:105px;
		display: block;
		padding:10px 30px;}
	.version-box>div{
		line-height:30px;
		display: block; text-align: center;}
	.version-option-txt{}
	.cell:after{
		content: '';
		display: block;
		clear: both;}
</style>
</body>
<script type="text/javascript">
    var vm = new Vue({
        el:'#app',
        data: {
            res:[],
            versionList:[],
	        versionOption:[],
	        apk:{
                apkKey:'anpxdAndroidErpApp'
	        }
        },
        methods: {

        },
    });

    var pageIndexNow = 1;

    $.ajax({
        type: "get",      //data 传送数据类型。post 传递
        dataType: 'json',  // 返回数据的数据类型json
        url: defaultUrl+"/controller/getApkNum",  // yii 控制器/方法
        cache: false,
        error:function(){
            alert("数据传输错误");
        },success: function (data) {

            console.log(data);
            if (data.code != 1) {
                return false
            }
            var pageTotal = data.result.total;
            var pageNumTotal = Math.ceil(pageTotal/20);
            $("#page").paging({
                pageNo:pageIndexNow,
                totalPage: pageNumTotal,
                totalSize: pageTotal,
                callback: function(num) {
                    pageIndexNow = num;
                    initList(num);
                }
            });
        }
    });

    function initList(pageIndex){
        $.ajax({
            type: "get",      //data 传送数据类型。post 传递
            dataType: 'json',  // 返回数据的数据类型json
            url: defaultUrl+"/controller/getApkList",  // yii 控制器/方法
            cache: false,
            data: {'pageIndex': pageIndex,'pageSize':'20'},  //传送的数据
            error:function(){
                alert("数据传输错误");
            },success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    return false
                }
                vm.res = data.result;
            }
        });
    }
    initList(1);

    function newApk(){

        $.get(defaultUrl+"/controller/getApkList?apkForce=0&apkKey="+$('#updateApkKey option:selected').val(),function(data1){
            vm.versionList = data1.result;
            vm.apk.apkUrl="https://www.anpxd.com/apk/erp/qiyuan.apk";
        },'json');
        $('#updateApkKey').change(function(){
            $.get(defaultUrl+"/controller/getApkList?apkForce=0&apkKey="+$('#updateApkKey option:selected').val(),function(data1){
                vm.versionList = data1.result;
                if($('#updateApkKey').val()=="anpxdAndroidErpApp"){
                    vm.apk.apkUrl="https://www.anpxd.com/apk/erp/qiyuan.apk";
                }else{
                    vm.apk.apkUrl="https://itunes.apple.com/us/app/%E5%90%AF%E8%BE%95%E6%B1%BD%E8%BD%A6/id1352712474?mt=8&uo=4";
                }
            },'json');
        })

        layer.open({
	        type: 1,
	        title:'新增Apk信息',
	        area: ['600px', '500px'],
	        fixed: false, //不固定
	        maxmin: true,
	        content: $('#updateApkForm'),
	        btn:['确定','取消'],
	        yes:function(){
	            $.ajax({
	                type: "get",      //data 传送数据类型。post 传递
	                dataType: 'json',  // 返回数据的数据类型json
	                url: defaultUrl + "/controller/insertApk",  // yii 控制器/方法
	                cache: false,
	                data: $('#updateApkForm').serializeJSON(),
	                error:function(){
	                    // alert("数据传输错误");
	                },success: function (data) {
                        if(data.code == 2){
                            layer.msg(data.msg);
                            return;
                        }
                        layer.closeAll();
                        layer.msg(data.msg);
                        location.reload();
	                }
	            });
	        },
	    });
    }

    function editApk(ele) {
        var _this = $(ele);
        $.ajax({
            type: "get",      //data 传送数据类型。post 传递
            dataType: 'json',  // 返回数据的数据类型json
            url: defaultUrl + "/controller/getApkList",  // yii 控制器/方法
            data: {"apkId": _this.attr("data-apkId")},
            cache: false,
            error: function () {
                // alert("数据传输错误");
            }, success: function (data) {
                console.log(data.result)
                vm.apk = data.result[0];

                $.get(defaultUrl+"/controller/getApkList?apkForce=0&apkKey="+data.result[0].apkKey,function(data1){
                    vm.versionList = data1.result;
                },'json');
            }
        });

        layer.open({
            type: 1,
            title: '修改Apk信息',
            area: ['600px', '500px'],
            fixed: false, //不固定
            maxmin: true,
            content: $('#updateApkForm'),
            btn: ['确定', '取消'],
            yes: function () {
                $.ajax({
                    type: "get",      //data 传送数据类型。post 传递
                    //contentType: "application/json",
                    dataType: 'json',  // 返回数据的数据类型json
                    url: defaultUrl + "/controller/updateApk?apkId=" + _this.attr("data-apkId"),  // yii 控制器/方法
                    cache: false,
                    data: $('#updateApkForm').serializeJSON(),
                    error: function () {
                        // alert("数据传输错误");
                    }, success: function (data) {
                        if(data.code == 2){
                            layer.msg(data.msg);
                            return;
                        }
                        layer.closeAll();
                        layer.msg(data.msg);
                        location.reload();
                    }
                });
            },
        });

        $('#updateApkKey').change(function(){
            $.get(defaultUrl+"/controller/getApkList?apkForce=0&apkKey="+$('#updateApkKey option:selected').val(),function(data1){
                vm.versionList = data1.result;
                if($('#updateApkKey option:selected').val()=="anpxdAndroidErpApp"){
                    vm.apk.apkUrl="https://www.anpxd.com/apk/erp/qiyuan.apk";
                }else{
                    vm.apk.apkUrl="https://itunes.apple.com/us/app/%E5%90%AF%E8%BE%95%E6%B1%BD%E8%BD%A6/id1352712474?mt=8&uo=4";
                }
            },'json');
        })
    }

</script>
</html>
